package com.sdp.th.netty.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.util.ResourceLeakDetector;

@Component
public class NettyServer{

	@Autowired
    private ServerBootstrap serverBootstrap;
 
	@Value("${sdp.netty.port}")
    private int nettyPort;
 
    private ChannelFuture serverChannelFuture;
    
    public boolean start() throws InterruptedException{
        serverChannelFuture = serverBootstrap.bind(nettyPort).sync();
        ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED);
//        CPU核心数
//        System.out.println(NettyRuntime.availableProcessors());
        if(serverChannelFuture.isSuccess()) {
        	return true;
        }
        return false;
    }

}
